<template>
  <div class="tab-pane fade" :id="id" role="tabpanel">
    <div class="card col-12">
      <div class="card-body">
        <div class="row mb-2">
          <div class="col-5 offset-md-3">
            <div class="form-check">
              <input
                type="checkbox"
                class="form-check-input"
                id="customCheck1"
                v-model="oneStepCreateOrder"
              />
              <label class="form-check-label" for="customCheck1"
                >新建订单时一步完成</label
              >
            </div>
          </div>
        </div>
        <div class="row mb-2">
          <div class="col-5 offset-md-3">
            <div class="form-check">
              <input
                type="checkbox"
                class="form-check-input"
                id="customCheck2"
                v-model="hideCustomerName"
              />
              <label class="form-check-label" for="customCheck2"
                >隐藏客户名称</label
              >
            </div>
            <span class="text-muted small"
              >只有订单创建人、管理员和财务角色能看到订单所属客户名称</span
            >
          </div>
        </div>
        <div class="row mb-2">
          <div class="col-5 offset-md-3">
            <div class="form-check">
              <input
                type="checkbox"
                class="form-check-input"
                id="customCheck3"
                v-model="isOnlySeeOwn"
              />
              <label class="form-check-label" for="customCheck2"
                >客服仅看自己的订单</label
              >
            </div>
            <span class="text-muted small">客服只能看到自己创建的订单</span>
          </div>
        </div>
        
        <div class="row mb-2">
          <div class="col-5 offset-md-3">
            <div class="form-check form-check-inline">
              <input
                class="form-check-input"
                type="radio"
                value="0"
                id="validationMode0"
                v-model="validationMode"
              />
              <label class="form-check-label">订单校验模式（宽松）</label>
            </div>
            <div class="form-check form-check-inline">
              <input
                class="form-check-input"
                type="radio"
                value="1"
                id="validationMode1"
                v-model="validationMode"
              />
              <label class="form-check-label">订单校验模式（严格）</label>
            </div>
            <br />
            <span class="text-muted small">订单数据校验时的模式</span>
          </div>
        </div>
        <div class="row mb-2">
          <div class="col-5 offset-md-3">
            <div class="form-check form-check-inline">
              <input
                class="form-check-input"
                type="radio"
                value="0"
                id="autoTicketMode0"
                v-model="autoTicketMode"
              />
              <label class="form-check-label">BSP开票(ETERM)</label>
            </div>
            <div class="form-check form-check-inline">
              <input
                class="form-check-input"
                type="radio"
                value="1"
                id="autoTicketMode1"
                v-model="autoTicketMode"
              />
              <label class="form-check-label">BSP开票(接口)</label>
            </div>
            <div class="form-check form-check-inline">
              <input
                class="form-check-input"
                type="radio"
                value="4"
                id="autoTicketMode4"
                v-model="autoTicketMode"
              />
              <label class="form-check-label">停用BSP自动开票</label>
            </div>
            <br />
            <span class="text-muted small">BSP自动开票时选择哪种开票方式</span>
          </div>
        </div>
        <div class="row mb-2">
          <div class="col-5 offset-md-3">
            <div class="form-check form-check-inline">
              <input
                class="form-check-input"
                type="radio"
                value="0"
                id="autoTicketSwitch0"
                v-model="autoTicketSwitch"
              />
              <label class="form-check-label">关闭</label>
            </div>
            <div class="form-check form-check-inline">
              <input
                class="form-check-input"
                type="radio"
                value="1"
                id="autoTicketSwitch1"
                v-model="autoTicketSwitch"
              />
              <label class="form-check-label">非工作时间</label>
            </div>
            <div class="form-check form-check-inline">
              <input
                class="form-check-input"
                type="radio"
                value="2"
                id="autoTicketSwitch2"
                v-model="autoTicketSwitch"
              />
              <label class="form-check-label">全天候7x24小时</label>
            </div>
            <br />
            <span class="text-muted small">BSP自动开票开关</span>
          </div>
        </div>

        <div class="row">
          <div class="col-4 offset-4">
            <button
              type="button"
              @click.stop="save()"
              class="btn btn-success "
            >
              保存
            </button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { searchEntOrderConfig, saveEntOrderConfig } from "@/api/admin.js";

export default {
  props: {
    id: {
      type: String,
    },
  },
  data() {
    return {
      oneStepCreateOrder: false,
      hideCustomerName: false,
      isOnlySeeOwn: false,
      autoTicketMode: 0,
      autoTicketSwitch: 0,
      validationMode: 0
    };
  },
  mounted: function () {
    this.search();
  },
  methods: {
    showErrMsg: function (msg, msgType) {
      this.$store.dispatch("showAlertMsg", {
        errMsg: msg,
        errMsgType: msgType,
      });
    },
    search: function () {
      searchEntOrderConfig((v) => {
        this.oneStepCreateOrder = v.oneStepCreateOrder === 1;
        this.hideCustomerName = v.hideCustomerName === 1;
        this.isOnlySeeOwn = v.isOnlySeeOwn === 1;
        this.autoTicketMode = v.autoTicketMode;
        this.autoTicketSwitch = v.autoTicketSwitch;
        this.validationMode = v.validationMode;
      });
    },
    save: function () {
      const params = {
        oneStepCreate: this.oneStepCreateOrder ? 1 : 0,
        hideCustomerName: this.hideCustomerName ? 1 : 0,
        onlySeeOwn: this.isOnlySeeOwn ? 1 : 0,
        autoTicketMode: this.autoTicketMode,
        autoTicketSwitch: this.autoTicketSwitch,
        validationMode: this.validationMode
      };

      saveEntOrderConfig(params, (v) => {
        if (v.status !== "OK") {
          this.showErrMsg(v.errmsg);
        } else {
          this.showErrMsg("保存成功");
          this.search();
        }
      });
    },
  },
};
</script>